﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/

using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// GeoMap Control
    /// </summary>
    [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal),
    DefaultProperty("ID"),
    ParseChildren(true, "ID"), Themeable(true),
    ToolboxData("<{0}:GeoMapControl runat=server></{0}:GeoMapControl>")]
    public class GeoMapControl : ChartControlBase
    {
       

        /// <summary>
        /// Gets or sets the chart settings.
        /// </summary>
        /// <value>The chart.</value>
        [Bindable(false),
        Category("Appearance"),
        Description("The Setting of the control")]
        public GeoMap Chart
        {
            get
            {
                var s = ViewState["Chart"] as GeoMap;
                return (s == null) ? null : s;
            }
            set
            {
                ViewState["Chart"] = value;
            }
        }


        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            ChartType = "geoMap";

            base.OnPreRender(e);
            string resourceName = "ElGee.Google.Charts.Controls.jquery-elgeeGoogleChart.js";

            ClientScriptManager cs = this.Page.ClientScript;
            cs.RegisterClientScriptResource(typeof(IntensityMapControl), resourceName);
        }

        /// <summary>
        /// Renders the HTML closing tag of the control into the specified writer. This method is used primarily by control developers.
        /// </summary>
        /// <param name="writer">A <see cref="T:System.Web.UI.HtmlTextWriter"/> that represents the output stream to render HTML content on the client.</param>
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            if (Chart != null)
            {
                Options = Chart.GetJsOptions();
                ChartHashKey = Chart.HashKey();
            }

            base.RenderEndTag(writer);
        }

    }
}
